// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.radio.globals;

import java.util.HashMap;
import java.util.Map;
import zombie.debug.DebugLog;
import zombie.debug.DebugType;

public final class RadioGlobalsManager {
    private final Map<String, RadioGlobal> globals = new HashMap();
    private final RadioGlobalInt bufferInt = new RadioGlobalInt("bufferInt", 0);
    private final RadioGlobalString bufferString = new RadioGlobalString("bufferString", "");
    private final RadioGlobalBool bufferBoolean = new RadioGlobalBool("bufferBoolean", false);
    private final RadioGlobalFloat bufferFloat = new RadioGlobalFloat("bufferFloat", 0.0F);
    private static RadioGlobalsManager instance;

    public static RadioGlobalsManager getInstance() {
        if (instance == null) {
            instance = new RadioGlobalsManager();
        }

        return instance;
    }

    private RadioGlobalsManager() {
    }

    public void reset() {
        instance = null;
    }

    public boolean exists(String name) {
        return this.globals.containsKey(name);
    }

    public RadioGlobalType getType(String name) {
        return this.globals.containsKey(name) ? ((RadioGlobal)this.globals.get(name)).getType() : RadioGlobalType.Invalid;
    }

    public String getString(String name) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null ? radioGlobal.getString() : null;
    }

    public boolean addGlobal(String name, RadioGlobal global) {
        if (!this.exists(name) && global != null) {
            this.globals.put(name, global);
            return true;
        } else {
            DebugLog.log(DebugType.Radio, "Error adding global: " + name + " to globals (already exists or global==null)");
            return false;
        }
    }

    public boolean addGlobalString(String name, String value) {
        return this.addGlobal(name, new RadioGlobalString(name, value));
    }

    public boolean addGlobalBool(String name, boolean value) {
        return this.addGlobal(name, new RadioGlobalBool(name, value));
    }

    public boolean addGlobalInt(String name, int value) {
        return this.addGlobal(name, new RadioGlobalInt(name, value));
    }

    public boolean addGlobalFloat(String name, float value) {
        return this.addGlobal(name, new RadioGlobalFloat(name, value));
    }

    public RadioGlobal getGlobal(String name) {
        return this.exists(name) ? (RadioGlobal)this.globals.get(name) : null;
    }

    public RadioGlobalString getGlobalString(String name) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null && radioGlobal instanceof RadioGlobalString ? (RadioGlobalString)radioGlobal : null;
    }

    public RadioGlobalInt getGlobalInt(String name) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null && radioGlobal instanceof RadioGlobalInt ? (RadioGlobalInt)radioGlobal : null;
    }

    public RadioGlobalFloat getGlobalFloat(String name) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null && radioGlobal instanceof RadioGlobalFloat ? (RadioGlobalFloat)radioGlobal : null;
    }

    public RadioGlobalBool getGlobalBool(String name) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null && radioGlobal instanceof RadioGlobalBool ? (RadioGlobalBool)radioGlobal : null;
    }

    public boolean setGlobal(String name, RadioGlobal value, EditGlobalOps operator) {
        RadioGlobal radioGlobal = this.getGlobal(name);
        return radioGlobal != null && value != null ? radioGlobal.setValue(value, operator) : false;
    }

    public boolean setGlobal(String name, String value) {
        this.bufferString.setValue(value);
        return this.setGlobal(name, this.bufferString, EditGlobalOps.set);
    }

    public boolean setGlobal(String name, int value) {
        this.bufferInt.setValue(value);
        return this.setGlobal(name, this.bufferInt, EditGlobalOps.set);
    }

    public boolean setGlobal(String name, float value) {
        this.bufferFloat.setValue(value);
        return this.setGlobal(name, this.bufferFloat, EditGlobalOps.set);
    }

    public boolean setGlobal(String name, boolean value) {
        this.bufferBoolean.setValue(value);
        return this.setGlobal(name, this.bufferBoolean, EditGlobalOps.set);
    }

    public CompareResult compare(RadioGlobal A, RadioGlobal B, CompareMethod compareMethod) {
        return A != null && B != null && A.getType().equals(B.getType()) ? A.compare(B, compareMethod) : CompareResult.Invalid;
    }

    public CompareResult compare(String globalA, String globalB, CompareMethod compareMethod) {
        return this.compare(this.getGlobal(globalA), this.getGlobal(globalB), compareMethod);
    }
}
